package com.example.weather_plus.ui.weatherforecast.view;

import android.os.Bundle;
import android.util.Log;
import android.widget.SearchView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import com.example.weather_plus.databinding.ActivitySearchBinding;
import com.example.weather_plus.ui.weatherforecast.viewmodel.GeoViewModel;

public class SearchActivity extends AppCompatActivity {

    ActivitySearchBinding binding;

    SearchView searchView;
    RecyclerView prefer_city;
    TextView tvtest;

    GeoViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySearchBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        searchView = binding.searchView;
        prefer_city = binding.recyclerViewSavedCities;

        tvtest = binding.tvTest;

        viewModel = new ViewModelProvider(this, new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(GeoViewModel.class);


//        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//            @Override
//            public boolean onQueryTextSubmit(String query) {
//
//
//                return true;
//            }
//
//            @Override
//            public boolean onQueryTextChange(String newText) {
//                return false;
//            }
//        });

        viewModel.setLocation("101010100");

        viewModel.getCityInfo().observe(
                this, post -> {
                    if (post != null) {
                        String info = post.getLocation().get(0).getAdm2();
                        tvtest.setText(info);
                        Log.e("CITY", info);
                    } else {
                        Log.e("WeatherView", "Received null CityInfo");
                    }
                }
        );


    }
}